class Solution {//leetcode130——被围绕的岛屿
private:
    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};
    void bfs(vector<vector<char>>&board,int i,int j){
        priority_queue<pair<int,int>> q;
        board[i][j]='.';
        q.push({i,j});
        while(q.size()){
            auto [a,b]=q.top();
            q.pop();
            for(int k=0;k<4;k++){
                int x=a+dx[k];
                int y=b+dy[k];
                if(x>=0&&x<m&&y>=0&&y<n&&board[x][y]=='O'){
                    board[x][y]='.';
                    q.push({x,y});
                }
            }
        }
    }
public: 
    void solve(vector<vector<char>>& board) { 
        }
        for(int j=1;j<n-1;j++){
            if(board[0][j]=='O') bfs(board,0,j);
            if(board[m-1][j]=='O') bfs(board,m-1,j);
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(board[i][j]=='O') board[i][j]='X';
                if(board[i][j]=='.') board[i][j]='O';
            }
        }
    }
private:
    int m;
    int n;
};